package com.yonyou.distribute.config;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CuratorConfig {

    @Bean
    public CuratorFramework curatorFramework(){
        // 初始化重试策略，间隔10s，重试3次
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(10000, 3);
        // 初始化客户端
        CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy);
        client.start();// 手动启动，否则很多方法或者功能不能正常使用
        return client;
    }
}
